rm(list = ls())
library(ggplot2)
library("reshape2")
library("plyr")
library(shape)
#library(xlsx)
library(foreign)
library(grid)
#library(cowplot)
#library(ggpubr)
library("readxl")

base30 <- read_excel("Results_summary.xlsx", sheet="Base30")
base40 <- read_excel("Results_summary.xlsx", sheet="Base40")
base3040 <- read_excel("Results_summary.xlsx", sheet="Base3040")

base30<-data.frame(base30)
base40<-data.frame(base40)
base3040<-data.frame(base3040)

#####BASELINE
#FIGURE2
ggplot(base3040, aes(x=year, y=LC_LA_30, color=Ind)) + 
  geom_line(aes(color=Ind), size=1) +
  #  xlim(2017, 2070)+
  #  ylim(0, 140000)+
  labs(x="Year", y="Total Operating Capacity (MW)")+
  scale_color_manual(name="Ind", 
                     labels = c("Lifetime = 30 years", 
                                "Lifetime = 40 years" 
                     ), 
                     values = c("A"="green", 
                                "C"="violetred1"))+
  guides(colour = guide_legend(title="Capacity Factor = 59.88%, Construction = 9%:", override.aes = list(size=4)))+
  scale_y_continuous(limits=c(0,140000), breaks = seq(0, 140000, by = 20000))+
  scale_x_continuous(expand = c(0.01, 0),limits=c(2017,2070), breaks = c(2017,2030,2040,2050,2060,2070))+
  theme_bw(base_size=10)+
  theme(
    axis.text.y = element_text(size=12, face="bold"),
    axis.text.x = element_text(size=12, face="bold"),
    #axis.ticks.x = element_text(size=12, face="bold"),
    #axis.line.x = element_line(color="black"),
    #axis.line.y = element_line(color="black"),
    axis.title=element_text(size=14),
    legend.text = element_text(size = 9, colour = "black"),
    legend.background = element_rect(fill = "white"),
    aspect.ratio = 0.7,
    legend.position = c(0.25, 0.20),
    #legend.position="none",
    #legend.title = element_blank(),
    #panel.border = element_blank(),
    #panel.background = element_blank(),
    #panel.grid.major = element_blank(),
    #panel.grid.minor = element_blank()
  )


#####COAL CAPACITY
data30 <- read_excel("Results_summary.xlsx", sheet="Sum30V3")
data40 <- read_excel("Results_summary.xlsx", sheet="Sum40V3")

df30<-data.frame(data30)
df40<-data.frame(data40)

#FIGURE 3a
ggplot(df30, aes(x=year, y=LC_LA_30, color=Ind)) + 
  geom_line(aes(color=Ind), size=1) +
  #  xlim(2017, 2070)+
  #  ylim(0, 140000)+
  labs(x="Year", y="Total Operating Capacity (MW)")+
  scale_color_manual(name="Ind", 
                     labels = c("Capacity Factor = 48%, Construction = 9%", 
                                "Capacity Factor = 48%, Construction = 24%",
                                "Baseline: Capacity Factor = 59.88%, Construction = 9%", 
                                "Capacity Factor = 62.28%, Construction = 9%", 
                                "Capacity Factor = 62.28%, Construction = 24%"), 
                     values = c("A"="#F8766D", 
                                "B"="#00BFC4", 
                                "C"="#000000",
                                "E"="#ff8000",
                                "F"="#0080ff"))+
  guides(colour = guide_legend(title="Scenario", override.aes = list(size=4)))+
  scale_y_continuous(limits=c(0,140000), breaks = seq(0, 140000, by = 20000))+
  scale_x_continuous(expand = c(0.01, 0),limits=c(2017,2070), breaks = c(2017,2030,2040,2050,2060,2070))+
  theme_bw(base_size=10)+
  theme(
    axis.text.y = element_text(size=12, face="bold"),
    axis.text.x = element_text(size=12, face="bold"),
    #axis.ticks.x = element_text(size=12, face="bold"),
    #axis.line.x = element_line(color="black"),
    #axis.line.y = element_line(color="black"),
    axis.title=element_text(size=14),
    legend.text = element_text(size = 7, colour = "black"),
    legend.background = element_rect(fill = "white"),
    aspect.ratio = 0.7,
    legend.position = c(0.25, 0.20),
    #legend.position="none",
    #legend.title = element_blank(),
    #panel.border = element_blank(),
    #panel.background = element_blank(),
    #panel.grid.major = element_blank(),
    #panel.grid.minor = element_blank()
  )

#FIGURE 3b
ggplot(df40, aes(x=year, y=LC_LA_40, color=Ind)) + 
  geom_line(aes(color=Ind), size=1) +
  #  xlim(2017, 2070)+
  #  ylim(0, 140000)+
  labs(x="Year", y="Total Operating Capacity (MW)")+
  scale_color_manual(name="Ind", 
                     labels = c("Capacity Factor = 48%, Construction = 9%", 
                                "Capacity Factor = 48%, Construction = 24%",
                                "Baseline: Capacity Factor = 59.88%, Construction = 9%", 
                                "Capacity Factor = 62.28%, Construction = 9%", 
                                "Capacity Factor = 62.28%, Construction = 24%"), 
                     values = c("A"="#F8766D", 
                                "B"="#00BFC4", 
                                "C"="#000000",
                                "E"="#ff8000",
                                "F"="#0080ff"))+
  guides(colour = guide_legend(title="Scenario", override.aes = list(size=4)))+
  scale_y_continuous(limits=c(0,140000), breaks = seq(0, 140000, by = 20000))+
  scale_x_continuous(expand = c(0.01, 0),limits=c(2017,2070), breaks = c(2017,2030,2040,2050,2060,2070))+
  theme_bw(base_size=10)+
  theme(
    axis.text.y = element_text(size=12, face="bold"),
    axis.text.x = element_text(size=12, face="bold"),
    #axis.ticks.x = element_text(size=12, face="bold"),
    #axis.line.x = element_line(color="black"),
    #axis.line.y = element_line(color="black"),
    axis.title=element_text(size=14),
    legend.text = element_text(size = 7, colour = "black"),
    legend.background = element_rect(fill = "white"),
    aspect.ratio = 0.7,
    legend.position = c(0.25, 0.20),
    #legend.position="none",
    #legend.title = element_blank(),
    #panel.border = element_blank(),
    #panel.background = element_blank(),
    #panel.grid.major = element_blank(),
    #panel.grid.minor = element_blank()
  )

#####NOW CO2
data30 <- read_excel("Results_summary co2.xlsx", sheet="Sum30V3")
data40 <- read_excel("Results_summary co2.xlsx", sheet="Sum40V3")

df30<-data.frame(data30)
df40<-data.frame(data40)

#FIGURE 4a
ggplot(df30, aes(x=year, y=LC_LA_30, color=Ind)) + 
  geom_line(aes(color=Ind), size=1) +
  #  xlim(2017, 2070)+
  #  ylim(0, 1200)+
  labs(x="Year", y="Annual CO2 Emissions (million tonnes)")+
  scale_color_manual(name="Ind", 
                     labels = c("Capacity Factor = 48%, Construction = 9%", 
                                "Capacity Factor = 48%, Construction = 24%",
                                "Baseline: Capacity Factor = 59.88%, Construction = 9%", 
                                "Capacity Factor = 62.28%, Construction = 9%", 
                                "Capacity Factor = 62.28%, Construction = 24%"), 
                     values = c("A"="#F8766D", 
                                "B"="#00BFC4", 
                                "C"="#000000",
                                "E"="#ff8000",
                                "F"="#0080ff"))+
  guides(colour = guide_legend(title="Scenario", override.aes = list(size=4)))+
  scale_y_continuous(limits=c(0,1200), breaks = seq(0, 1200, by = 100))+
  scale_x_continuous(expand = c(0.01, 0),limits=c(2017,2070), breaks = c(2017,2030,2040,2050,2060,2070))+
  theme_bw(base_size=10)+
  theme(
    axis.text.y = element_text(size=12, face="bold"),
    axis.text.x = element_text(size=12, face="bold"),
    #axis.ticks.x = element_text(size=12, face="bold"),
    #axis.line.x = element_line(color="black"),
    #axis.line.y = element_line(color="black"),
    axis.title=element_text(size=14),
    legend.text = element_text(size = 7, colour = "black"),
    legend.background = element_rect(fill = "white"),
    aspect.ratio = 0.7,
    legend.position = c(0.25, 0.20),
    #legend.position="none",
    #legend.title = element_blank(),
    #panel.border = element_blank(),
    #panel.background = element_blank(),
    #panel.grid.major = element_blank(),
    #panel.grid.minor = element_blank()
  )

#FIGURE 4b

ggplot(df40, aes(x=year, y=LC_LA_40, color=Ind)) + 
  geom_line(aes(color=Ind), size=1) +
  #  xlim(2017, 2070)+
  #  ylim(0, 1200)+
  labs(x="Year", y="Annual CO2 Emissions (million tonnes)")+
  scale_color_manual(name="Ind", 
                     labels = c("Capacity Factor = 48%, Construction = 9%", 
                                "Capacity Factor = 48%, Construction = 24%",
                                "Baseline: Capacity Factor = 59.88%, Construction = 9%", 
                                "Capacity Factor = 62.28%, Construction = 9%", 
                                "Capacity Factor = 62.28%, Construction = 24%"), 
                     values = c("A"="#F8766D", 
                                "B"="#00BFC4", 
                                "C"="#000000",
                                "E"="#ff8000",
                                "F"="#0080ff"))+
  guides(colour = guide_legend(title="Scenario", override.aes = list(size=4)))+
  scale_y_continuous(limits=c(0,1200), breaks = seq(0, 1200, by = 100))+
  scale_x_continuous(expand = c(0.01, 0),limits=c(2017,2070), breaks = c(2017,2030,2040,2050,2060,2070))+
  theme_bw(base_size=10)+
  theme(
    axis.text.y = element_text(size=12, face="bold"),
    axis.text.x = element_text(size=12, face="bold"),
    #axis.ticks.x = element_text(size=12, face="bold"),
    #axis.line.x = element_line(color="black"),
    #axis.line.y = element_line(color="black"),
    axis.title=element_text(size=14),
    legend.text = element_text(size = 7, colour = "black"),
    legend.background = element_rect(fill = "white"),
    aspect.ratio = 0.7,
    legend.position = c(0.25, 0.20),
    #legend.position="none",
    #legend.title = element_blank(),
    #panel.border = element_blank(),
    #panel.background = element_blank(),
    #panel.grid.major = element_blank(),
    #panel.grid.minor = element_blank()
  )

#####NOW CUMULATIVE CO2

data30 <- read_excel("Results_summary co2 cumul.xlsx", sheet="Sum30V3")
data40 <- read_excel("Results_summary co2 cumul.xlsx", sheet="Sum40V3")

df30<-data.frame(data30)
df40<-data.frame(data40)

#FIGURE 5a

ggplot(df30, aes(x=year, y=LC_LA_30, color=Ind)) + 
  geom_line(aes(color=Ind), size=1) +
  #  xlim(2017, 2070)+
  #  ylim(0, 38000)+
  labs(x="Year", y="Cumulative CO2 Emissions from 2017 (million tonnes)")+
  scale_color_manual(name="Ind", 
                     labels = c("Capacity Factor = 48%, Construction = 9%", 
                                "Capacity Factor = 48%, Construction = 24%",
                                "Baseline: Capacity Factor = 59.88%, Construction = 9%", 
                                "Capacity Factor = 62.28%, Construction = 9%", 
                                "Capacity Factor = 62.28%, Construction = 24%"), 
                     values = c("A"="#F8766D", 
                                "B"="#00BFC4", 
                                "C"="#000000",
                                "E"="#ff8000",
                                "F"="#0080ff"))+
  guides(colour = guide_legend(title="Scenario", override.aes = list(size=4)))+
  scale_y_continuous(limits=c(0,40000), breaks = seq(0, 40000, by = 2000))+
  scale_x_continuous(expand = c(0.01, 0),limits=c(2017,2070), breaks = c(2017,2030,2040,2050,2060,2070))+
  theme_bw(base_size=10)+
  theme(
    axis.text.y = element_text(size=12, face="bold"),
    axis.text.x = element_text(size=12, face="bold"),
    #axis.ticks.x = element_text(size=12, face="bold"),
    #axis.line.x = element_line(color="black"),
    #axis.line.y = element_line(color="black"),
    axis.title=element_text(size=14),
    legend.text = element_text(size = 9, colour = "black"),
    legend.background = element_rect(fill = "white"),
    aspect.ratio = 0.7,
    legend.position = c(0.75, 0.20),
    #legend.position="none",
    #legend.title = element_blank(),
    #panel.border = element_blank(),
    #panel.background = element_blank(),
    #panel.grid.major = element_blank(),
    #panel.grid.minor = element_blank()
  )


#FIGURE 5b
ggplot(df40, aes(x=year, y=LC_LA_40, color=Ind)) + 
  geom_line(aes(color=Ind), size=1) +
  #  xlim(2017, 2070)+
  #  ylim(0, 40000)+
  labs(x="Year", y="Cumulative CO2 Emissions from 2017 (million tonnes)")+
  scale_color_manual(name="Ind", 
                     labels = c("Capacity Factor = 48%, Construction = 9%", 
                                "Capacity Factor = 48%, Construction = 24%",
                                "Baseline: Capacity Factor = 59.88%, Construction = 9%", 
                                "Capacity Factor = 62.28%, Construction = 9%", 
                                "Capacity Factor = 62.28%, Construction = 24%"), 
                     values = c("A"="#F8766D", 
                                "B"="#00BFC4", 
                                "C"="#000000",
                                "E"="#ff8000",
                                "F"="#0080ff"))+
  guides(colour = guide_legend(title="Scenario", override.aes = list(size=4)))+
  scale_y_continuous(limits=c(0,40000), breaks = seq(0, 40000, by = 2000))+
  scale_x_continuous(expand = c(0.01, 0),limits=c(2017,2070), breaks = c(2017,2030,2040,2050,2060,2070))+
  theme_bw(base_size=10)+
  theme(
    axis.text.y = element_text(size=12, face="bold"),
    axis.text.x = element_text(size=12, face="bold"),
    #axis.ticks.x = element_text(size=12, face="bold"),
    #axis.line.x = element_line(color="black"),
    #axis.line.y = element_line(color="black"),
    axis.title=element_text(size=14),
    legend.text = element_text(size = 9, colour = "black"),
    legend.background = element_rect(fill = "white"),
    aspect.ratio = 0.7,
    legend.position = c(0.75, 0.20),
    #legend.position="none",
    #legend.title = element_blank(),
    #panel.border = element_blank(),
    #panel.background = element_blank(),
    #panel.grid.major = element_blank(),
    #panel.grid.minor = element_blank()
  )











